package org.mch.swingm.ext;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import org.mch.swingm.core.MComboBox;
import org.mch.swingm.core.MLabel;
import org.mch.swingm.itf.IMExtComponent;
import org.mch.swingm.obj.MItem;

public class MEComboBox<T> extends JPanel implements IMExtComponent {

	private MItem item;

	public MEComboBox() {
		super();
		initGUI();
	}

	public MEComboBox(MItem item) {
		super();
		this.item = item;
		initGUI();
	}

	private void initGUI() {
		setLayout(new BorderLayout(0, 0));
		add(getLabel(), BorderLayout.WEST);
		add(getComponent(), BorderLayout.CENTER);
	}

	private static final long serialVersionUID = -8692238566578724351L;
	private MLabel label;
	private MComboBox<T> comboBox;

	public MLabel getLabel() {
		if (label == null) {
			label = new MLabel("New label");
		}
		return label;
	}

	public MComboBox<T> getComponent() {
		if (comboBox == null) {
			comboBox = new MComboBox<T>();
		}
		return comboBox;
	}

	@Override
	public void setValue(Object s) {
	}

	@Override
	public Object getValue() {
		return getComponent().getSelectedItem();
	}

	public MItem getItem() {
		return item;
	}

	public String getKey() {
		return getItem().getKey();
	}

}
